<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="root">
    <h2>学校名称：{{school.name}}</h2>
    <h2>学校地址：{{school.address}}</h2>
    <h2 v-if="school.leader">校长：{{school.leader}}</h2>
    <hr>
    <h1>学生信息</h1>
    <button @click="addSex">添加一个性别属性，默认值是男</button>
    <h2>学生姓名：{{student.name}}</h2>
    <h2 v-if="student.sex">学生性别：{{student.sex}}</h2>
    <h2>学生年龄：真实：{{student.age.rAge}}，对外：{{student.age.sAge}}</h2>
    <h2>朋友们</h2>
    <ul>
      <li v-for="(f, index) in student.friends" :key="index">
        {{f.name}}--{{f.age}}
      </li>
    </ul>
  </div>
  <script>
    Vue.config.productionTip = false

    const vm = new Vue({
      el: '#root',
      data: {
        school: {
          name: 'ccc',
          address: 'ch',
          // leader: '',
        },
        student: {
          name: 'tom',
          age: {
            rAge: 40,
            sAge: 29
          },
          // sex: '男',
          friends: [
            { name: 'jerry', age: 35 },
            { name: 'tony', age: 36 }
          ]
        }
      },
      methods: {
        addSex() {
          this.$set(this.student, 'sex', 'male')
        }
      },
    })

  </script>
</body>

</html>